<?php
/**
 * *
 *  * ============================================================================
 *  * Created by PhpStorm.
 *  * User: Ice
 *  * 邮箱: ice@sbing.vip
 *  * 网址: https://sbing.vip
 *  * Date: 2019/9/19 下午3:33
 *  * ============================================================================.
 */

namespace app\api\controller;

use app\admin\model\Config;
use app\common\model\Upload;
use app\common\controller\Api;


/**
 * 公共接口.
 */
class Common extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = '*';

   public function config(){
       //说明
       $config = (new Config())->where(['group' => 'base'])->column('value','name');
//      foreach ($config as $key => &$value){
//          $value = $this->get_img_thumb_url($value,config('app.api_url'));
//      }
       $this->success('获取成功',$config);
   }

    public function get_img_thumb_url($content = "", $suffix = "")
    {
        $pregRule = "/<[img|IMG].*?src=[\'|\"](.*?(?:[\.jpg|\.jpeg|\.png|\.gif|\.bmp]))[\'|\"].*?[\/]?>/";
        $content = preg_replace($pregRule, '<img src="' . $suffix . '${1}" style="max-width:100%">', $content);
        return $content;
    }

    public function upload(){
        $file = request()->file('file');
        $data = Upload::uploadImages($file);
        $data['code'] == 200 ? $this->success($data['msg'],$data['data']) : $this->error($data['msg']);
    }
}
